package com.feihao.demoDate;

import javafx.scene.input.DataFormat;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.util.Calendar;
import java.util.Date;

//用程序判断2018年2月14日是星期几。
public class Demo02 {
    public static void main(String[] args) throws ParseException {
        String s = "2018年2月14日";

        //解析为date对象：
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy年M月dd日");
        LocalDate parse = LocalDate.parse(s, dateTimeFormatter);
        System.out.println(parse);

        DayOfWeek dayOfWeek = parse.getDayOfWeek();
        System.out.println(dayOfWeek);

        System.out.println("============");

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
        Date parse1 = simpleDateFormat.parse(s);
        Calendar c = Calendar.getInstance();
        c.setTime(parse1);

        int i = c.get(Calendar.DAY_OF_WEEK); //1-7代表星期天-星期六
        System.out.println(i);

        String week = getWeek(i);
        System.out.println(week);
    }

    private static String getWeek(int i) {
        String[] week= {"","星期日","星期1","星期2","星期3","星期4","星期5","星期6"};
        return  week[i];
    }


}
